<template>
  <view class="system">
        <view class="system-body">
            <view class="system-item s-b">
                    <view>分享码</view>
                    <view class="code">{{code}} <view class="c-s" @click="copy">复制</view> </view>
            </view>

            <view class="system-item">
                    <view>已绑定分享码</view>
                    <view v-if="!showCode" style="width: 50%;"><fui-input v-model="inputCode" borderTop placeholder="请输入分享码"></fui-input></view>
                    <view v-if="!showCode" @click="binding" class="c-s">绑定</view>

                    <view>{{showCode}}</view>
            </view>
        </view>

        <view class="system-body">
            <view class="system-item s-b">
                <view class="icon-content"> <fui-icon size="35" name="notice"></fui-icon>  <text>审核通知</text></view>
                <fui-switch checked></fui-switch>
            </view>

            <view class="system-item s-b">
                <view class="icon-content"> <fui-icon size="35" name="notice"></fui-icon>  <text>支付通知</text></view>
                <fui-switch checked></fui-switch>
            </view>
        </view>


        <view class="system-body">
            <view class="system-item s-b" v-for="item in systemList" :key="item.title">
                    <view class="icon-content"> <fui-icon size="35" :name="item.icon"></fui-icon>  <text>{{item.title}}</text></view>
                    <fui-icon size="35" name="arrowright"></fui-icon>
            </view>
        </view>



  </view>
</template>

<script setup lang="ts">
import dyUserCodeService from "@/api/dyUserCodeService";
const code = ref() 
const inputCode = ref()
const showCode = ref()

const systemList = ref([
    {
        title:"服务协议",
        url:"",
        icon:"order"
    },
    {
        title:"隐私政策",
        url:"",
        icon:"lock"
    },
    {
        title:"退出登录",
        url:"",
        icon:"rotate"
    }
])

const copy = ()=>{
    uni.setClipboardData({
	data: code.value,
	success: function () {
		uni.showToast({
            title:"复制成功"
        })
	}
})
}

const binding = async()=>{
    if(!inputCode.value){
        uni.showToast({
            title:"请输入"
        })
        return
    }
    try{
        const {success} = await dyUserCodeService.bindingCode({code:inputCode.value})
        if(success){
            showCode.value = inputCode.value
        }
    }catch(e:any){
        uni.showToast({
            title:e.message
        })
    }
}

const getCodeData =async ()=>{
    const {success,result} = await dyUserCodeService.getBindingCode()
    if(success){
        code.value = result.code
        showCode.value = result.bindingInviteCode
    }
}
onLoad(()=>{
    getCodeData()
})


</script>

<style lang="scss" scoped>
page{
    height: 100%;
}
.system{
    background: rgb(248,248,248);
    height: 100%;
    padding: 20rpx;
    .system-body{
        margin-top: 20rpx;
        background: white;
        border-radius: 20rpx;
        font-size: 28rpx;
        padding: 0 20rpx;
    }
    
    .system-item{
        height: 100rpx;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .code{
            display: flex;
        }
        .c-s{
                font-size: 23rpx;
                padding: 5rpx 20rpx;
                background: #86baff;
                border-radius: 20rpx;
                margin-left: 28rpx;
            }
        .icon-content{
            display: flex;
            align-items: center;
            text{
                margin-left: 10rpx;
            }
        }
    }
    .s-b{
        border-bottom: 1rpx solid rgb(235, 235, 235);
    }
}

</style>
